<?php
/**
 * Created by PhpStorm.
 * User: cc
 * Date: 2022/4/8
 * Time: 5:31 下午
 */

namespace app\common\cachemodel;

use app\common\model\BaseCache;
use think\Cache;
use think\Log;
use XznsTools\cache\CacheManage;

/**
 * Class AppUserReply
 * @package app\common\cachemodel
 */
class AppUserReply extends BaseCache
{
    protected $table = 'wechat_backup_07_18_14_43_00.app_user_reply';
    protected $cacheModel = 'user.read_reply';

    /**
     * 回复我的已读
     * @param $uid
     * @param $ids
     */
    public function replyRead($uid, $ids)
    {
        //  回复我的消息已读
        try
        {
            if ($ids)
            {
                $unread_ids_arr = [];
                foreach ($ids as $k => $v)
                {
                    $unread_ids_arr[] = [
                        'reply_id' => $v,
                        'uid' => $uid,
                    ];
                }
                $this->insertAll($unread_ids_arr);
                $ids = keyValue($ids);
                CacheManage::getInstance()->setCacheConfig('user.read_reply', $uid)->listAdd($ids);
                Cache::rm('read_reply_' . $uid);
            }
        }
        catch (\Exception $e)
        {
            Log::write('用户回复我的已读失败：【' . $e->getFile() . $e->getLine() . '】', 'error', true);
        }
    }
}
